import {
  Column,
  CreateDateColumn,
  Entity,
  JoinTable,
  ManyToMany,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';
import { RoleManage } from '../../roleManage/entities/roleManage.entity';

@Entity()
export class MenuManage {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  name: string;

  @Column()
  path: string;

  @Column({ nullable: true })
  component: string;

  @Column({ nullable: true })
  parent_id: number;

  @Column({ nullable: true })
  icon: string;

  @Column({ nullable: true })
  sort: number;

  @Column({ default: true })
  is_show: boolean;

  @CreateDateColumn()
  created_at: Date;

  @UpdateDateColumn()
  updated_at: Date;

  @ManyToMany(() => RoleManage, (role) => role.menus)
  @JoinTable({
    name: 'role_menu', // 指定连接表名称
    joinColumn: { name: 'menu_id' },
    inverseJoinColumn: { name: 'role_id' },
  })
  role: RoleManage;
}
